package com.xizi.秋招笔试;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-15下午 07:58
 */
public class Test2 {
    public static void main(String[] args) {
        System.out.println(findInterval("abcdefghijklmnopqrstuvw???xyz"));
    }

    public static int findInterval(String str) {
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < str.length() - 26; i++) {
            for (int j = i + 26; j <= str.length(); j++) {
                String str1 = str.substring(i, j);
                int count = 0;
                if (str1.length() < 26) break;
                for (int k = 0; k < str1.length(); k++) {
                    if (str1.charAt(k) == '?') {
                        count++;
                    }
                    boolean res1 = str1.chars().filter(a -> a >= 'a' && a <= 'z').distinct().count() == (26 - count);
                    if (res1) {
                        res = Math.min(res, j - i);
                    }
                }
            }
        }
        return res == Integer.MAX_VALUE ? -1 : res;
    }

}
